/**
 * 
 */
package javbot.keydata;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

public class KeyDataProps extends Properties{
	
	private static final long serialVersionUID = -8073438714334544270L;
	public final static File file = new File("KeyData.txt");
	private final KeyData data;

	KeyDataProps(KeyData data) {
		this.data = data;
	}



	public void readKeyData() throws FileNotFoundException, IOException{
		load(new FileInputStream(file));
		for (int i=0;i<256;i++) {
			data.vkCodes[i] = data.new KeyComb();
			String tmp[] = getProperty("ASCII_" + i).split("\\|");
			data.vkCodes[i].vkCode = Integer.parseInt(tmp[0]);
			data.vkCodes[i].shift = Boolean.parseBoolean(tmp[1]);
			
		}
	}
	
	public void writeKeyData() throws FileNotFoundException, IOException{
		
		for (int i=0;i<256;i++) {
			setProperty("ASCII_" + i, this.data.vkCodes[i].toString());
		}
		
		store(new FileOutputStream(file),"Key Mappings");
	}		
	
}